package com.zhuannimei.parser;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.zhuannimei.domain.ProductHistory;

public class ProductHistoryParser extends BaseJSONParser<List<ProductHistory>> {

	@Override
	public List<ProductHistory> parseJSON(String jsonstr) throws JSONException {
		List<ProductHistory> list = new ArrayList<ProductHistory>();
		JSONObject jo = new JSONObject(jsonstr);
		JSONArray jsonArray = jo.getJSONArray("result");
		for (int i = 0; i < jsonArray.length(); i++) {
			JSONObject obj = jsonArray.getJSONObject(i);
			ProductHistory pro = new ProductHistory();
			pro.setCtime(obj.optString("ctime"));
			pro.setDescribe(obj.optString("describe"));
			pro.setId(UUID.randomUUID()+"");
			pro.setNumber(obj.optString("number"));
			pro.setPicture(obj.optString("picture"));
			pro.setPoint(obj.optString("point"));
			pro.setPrice(obj.optString("price"));
			pro.setProductId(obj.optString("productId"));
			pro.setTitle(obj.optString("title"));
			list.add(pro);
		}
		return list;
	}

}
